﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using com.pro2e.console.service.auth.vo;
using com.pro2e.console.service.log.vo;

/// <summary>
/// SessionHelper 的摘要描述
/// </summary>
/// 

namespace com.pro2e.web.util
{

    public class SessionHelper : System.Web.UI.Page
    {
        log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        private readonly string LOGIN_USER = "LOGIN_USER";
        private readonly string MENU_STATUS_OPEN = "MENU_STATUS_OPEN";
        private readonly string LOGVO = "LOG_VO";
        private readonly string TMP_SS = "TMP_SESSION";
        private readonly string MENU_FUNCTION_NAME = "MENU_FUNCTION_NAME";
        private readonly string LOGIN_USER_BELONGTOBRANCH = "LOGIN_USER_BELONGTOBRANCH";


        /// <summary>
        ///  目前的後台清單是否開啟
        /// </summary>
        public bool MenuStatusOpen
        {
            get { return ((Session[MENU_STATUS_OPEN] == null || String.IsNullOrEmpty(Session[MENU_STATUS_OPEN].ToString())) ? true : (bool)Session[MENU_STATUS_OPEN]); }

            set { Session[MENU_STATUS_OPEN] = value; }
        }

        /// <summary>
        /// 使用者的資訊
        /// </summary>
        public LoginUser LoginUser
        {
            get
            {
                try
                {
                    return (Session[LOGIN_USER] == null ? null : (LoginUser)Session[LOGIN_USER]);
                }
                catch
                {
                    // log.Error(ex);
                    return null;
                }
            }

            set { Session[LOGIN_USER] = value; }
        }

        /// <summary>
        /// for 一般暫存或傳值用
        /// </summary>
        public string MenuFuncName
        {
            get { return (Session[MENU_FUNCTION_NAME] == null ? "" : Session[MENU_FUNCTION_NAME].ToString()); }

            set { Session[MENU_FUNCTION_NAME] = value; }
        }

        /// <summary>
        /// for 一般暫存或傳值用
        /// </summary>
        public object TmpSS
        {
            get { return (Session[TMP_SS] == null ? null : Session[TMP_SS]); }

            set { Session[TMP_SS] = value; }
        }


        /// <summary>
        /// 異動檔Log
        /// </summary>
        public LogSystemVO LogVO
        {
            get
            {
                if (Session[LOGVO] == null)
                {
                    return new LogSystemVO();
                }
                else
                {
                    try
                    {
                        return (LogSystemVO)Session[LOGVO];
                    }
                    catch
                    {
                        return new LogSystemVO();
                    }
                }
            }
            set { Session[LOGVO] = value; }
        }

        /// <summary>
        ///  登入使用者的BranchNo
        /// </summary>
        public string LoginUserBelongToBranchNo
        {
            get { return (Session[LOGIN_USER_BELONGTOBRANCH] == null ? "" : Session[LOGIN_USER_BELONGTOBRANCH].ToString()); }

            set { Session[LOGIN_USER_BELONGTOBRANCH] = value; }
        }
    }
}